package LC.hash;

public class LC242 {
    public static void main(String[] args) {
        String s = "anagram";
        String t = "nagaram";
        System.out.println(isAnagram(s, t));
    }

    public static boolean isAnagram(String s, String t) {
        char[] chars = s.toCharArray();
        char[] chart = t.toCharArray();
        int sLength = chars.length, tLength = chart.length;
        int[] hash = new int[128];
        for (int i = 0; i < tLength; i++) {
            hash[chart[i]]--;
        }
        for (int i = 0; i < sLength; i++) {
            hash[chars[i]]++;
        }
        for (int i = 0; i < 128; i++) {
            if (hash[i] != 0) {
                return false;
            }
        }
        return true;
    }
}
